import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'queryResult',
  components: {},
  data () {
    return {
      studentId: '',
      siteId: '',
      keyWords: '',
      status: '',
      reserveNo:'',
      paySerial:'',
      applyFee:'',
      contentListShow: false,
      content: {},
      contents: {
        applyStatus:1,
        className:'',
        applyFee:'',
        beginTime:'',
        classId:'',
        spelName:'',
        studentName:'',
        classTimeable:'',
        isPayable:'',
        endDate:''
      }
    }
  },
  mounted () {
    var _this = this
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.reserveNo = this.$route.query.reserveNo
    _this.goList()
  },
  methods: {
    goList () {
      var _this = this
      http.get('http://47.96.62.199/eduplatform/api/public/px/apply/getDetailByReserveNo' + '?orgId=' + _this.siteId + '&reserveNo=' + _this.reserveNo, {
      }, (res) => {
        console.log(res)
        if (res.code != 0) {
          alert(res.msg)
        } else {
          _this.contentListShow = true
          _this.paySerial = res.data.pay.paySerial
          _this.contents.applyFee = res.data.class.feeTotal
          _this.applyFee = _this.contents.applyFee
          _this.contents.beginTime = _this.dateFormat(res.data.class.bean.beginDate)
          _this.contents.endDate = _this.dateFormat(res.data.class.bean.endDate)
          _this.contents.classId = res.data.apply.classId
          _this.contents.spelName = res.data.class.caption.spelId
          _this.contents.studentName = res.data.student.name
          _this.contents.classTimeable = res.data.class.classSchedule
          _this.contents.isPayable = res.data.pay.status
          _this.contents.className = res.data.class.bean.name
          _this.contents.area = res.data.class.caption.area
          _this.contents.year = res.data.class.caption.year
          _this.contents.term = res.data.class.caption.term
          _this.contents.spelName = res.data.class.caption.spelId
          _this.contents.degree = res.data.class.caption.degree
          _this.contents.classNo = res.data.class.bean.code
          let status = res.data.apply.status
          _this.contents.applyStatusName = _this.applyStatus(status)
        }
      })
    },
    applyStatus(status) {
      if (status == 1) {
        return '可缴费'
      } else if (status == 2) {
        return  '已代缴'
      } else if(status == 3) {
        return '已缴费'
      } else if (status == 4) {
        return '已退费'
      } else if (status == 5) {
        return '已失效'
      } else if (status == 6) {
        return '已撤销'
      }
    },
    comeBack () {
      window.history.go(-1)
    },
    goPayment: function (id) {
      if (this.contents.isPayable) {
        var query = {paySerial:this.paySerial,reserveNo:this.reserveNo,name:this.contents.className,totalFees:this.applyFee,area:this.contents.area,classNo:this.contents.classNo,frontStatusName:this.contents.frontStatusName,year:this.contents.year,term:this.contents.term,spelName:this.contents.spelName,degree:this.contents.degree,studentName:this.contents.studentName}
        this.$router.push({path: '/payment',query:query})
      }
    },
    dateFormat(longTypeDate) {
      var dateType = "";
      var date = new Date();
      date.setTime(longTypeDate);
      dateType += date.getFullYear();  //年
      dateType += "-" + this.getMonth(date); //月
      dateType += "-" + this.getDay(date);  //日
      return dateType;
    },
    getMonth(date) {
      var month = "";
      month = date.getMonth() + 1; //getMonth()得到的月份是0-11
      if(month<10){
        month = "0" + month;
      }
      return month;
    },
    getDay(date) {
      var day = "";
      day = date.getDate();
      if(day<10){
        day = "0" + day;
      }
      return day;
    }
  }
}
